<?php
$servername = "localhost";
$username = "root";
$password = "";
 
// 创建连接
$conn = mysqli_connect($servername, $username, $password);
 
// 检测连接
if (!$conn) {
    die("连接失败: " .  mysqli_connect_error());
} 
echo "连接成功",'<br>';
//(1)
$sql = "SELECT * FROM student WHERE 年龄 BETWEEN 18 AND 22;";
$result = mysqli_query($conn, $sql);
 
if (mysqli_num_rows($result) > 0) {
    // 输出数据
    while($row = mysqli_fetch_assoc($result)) {
        echo $row;
    }
} else {
    echo "0 结果";
}
//(2)
if (mysqli_connect_errno())
{
    echo "连接失败: " . mysqli_connect_error();
}

mysqli_query($conn,"UPDATE student SET 学号='001'
WHERE WHERE 学号='081'"
);

//(3)
if (!$conn) {
    die("连接失败: " . mysqli_connect_error());
}
 
$sql2 = 'SELECT student.学号,姓名 
   FROM student,choose 
   WHERE student.学号=choose.学号 AND 课程号=5';
$result2 = mysqli_query($conn, $sql2);
 
if (mysqli_num_rows($result2) > 0) {
    // 输出数据
    while($row2 = mysqli_fetch_assoc($result2)) {
        echo "学号: " . $row2["学号"]. " 姓名: " . $row2["姓名"].  "<br>";
    }
} else {
    echo "0 结果";
}
//(4)
$result3 = mysqli_query($conn,"SELECT * FROM choose ORDER BY 成绩 DESC;");

while($row3 = mysqli_fetch_array($result3))
{
    echo $row3['成绩'];
    echo $row3['姓名'];
    echo $row3['学号'];
    echo "<br>";
}
//(5)
mysqli_query($conn,"DELETE FROM student
WHERE 学号='002'");
//(6)
ALTER TABLE student
ADD 地址 char;
//格式不会啊


//(7)
DROP TABLE student;
//ememem格式也不会啊

mysqli_close($conn);

?>

